import { navigateTo } from '../../utils/util';
Page({

    data: {
        test:false,
        dine_way:true,
        address:{},
        isEmpty_address: true,
        textarea_num: '50',
        order_details:[
            {
                name: '鸡米花',
                num: '8',
                distance: '',
                price: '48'
            },
            {
                name: '餐盒',
                num: '',
                distance: '',
                price: '2.35'
            },
            {
                name: '配送费',
                num: '',
                distance: '',
                price: '4'
            }
        ]
    },
    // 选择地址
    address:function(){
        const that = this;
        let addr = {},status;

        wx.chooseAddress({
            success: function (res) {
                console.log(res)
                addr.userName = res.userName;
                addr.postalCode = res.postalCode;
                addr.provinceName = res.provinceName;
                addr.countyName = res.countyName;
                addr.detailInfo = res.detailInfo;
                addr.nationalCode = res.nationalCode;
                addr.telNumber = res.telNumber;
                addr.cityName = res.cityName;
                
                that.setData({
                    address: addr,
                    isEmpty_address:false
                });

            }
        });
    },
    // 就餐方式
    dine_way:function(e){
        const tip = e.target.dataset.tip;
        let status;
        tip == 0 ? status = true : status = false;
        this.setData({
            dine_way: status
        });
    },
    // 表单提交/页面跳转
    submit:function(){
        navigateTo('success')
    },
    textarea:function(e){
        let length = 50 - e.detail.value.length;
        this.setData({
            textarea_num: length
        });
    },
    isEmpty_obj:function(obj){
        let status =  true;
        for (let i in obj) {
            status = false
        };
        return status;
    },
    onLoad: function (options) {
        console.log(options)
        const that= this;
        setTimeout(_=>{
            that.setData({
                a:true
            })
        });
    }
})